﻿<Window x:Class="SellAvi.Views.WindowUserList"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:command="http://www.galasoft.ch/mvvmlight"
        xmlns:converters="clr-namespace:SellAvi.Views.Converters"
        Title="Список пользователей для авторизации"
        Width="620"
        
        DataContext="{Binding Main, Source={StaticResource Locator}}">
    <Window.Resources>
        <converters:AvitoUserPhoneConverter x:Key="apc" />
    </Window.Resources>
    <Grid>
        <ItemsControl ItemsSource="{Binding AvitoUsers}" Margin="10">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Grid x:Name="UserItem">
                        <Grid.Resources>
                            <Style TargetType="{x:Type Label}">
                                <Setter Property="Padding" Value="0,2,5,0" />
                                <Setter Property="FontSize" Value="10"></Setter>
                                <Setter Property="FontWeight" Value="DemiBold"></Setter>

                            </Style>
                        </Grid.Resources>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="20"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>

                        <StackPanel Grid.Column="0" DataContext="{Binding Main, Source={StaticResource Locator}}">
                            <Separator Height="12" Visibility="Hidden"></Separator>
                            <Button Command="{Binding LogInAsUserCommand}" CommandParameter="{Binding ElementName=UserItem,Path=DataContext}" ToolTip="Войти в магазин из-под этого пользователя" Width="20">
                                <Image Source="/SellAvi;component/Resources/user.png"></Image>
                            </Button>
                            <Button Command="{Binding RefreshUserInformationCommand}" CommandParameter="{Binding ElementName=UserItem, Path=DataContext}" ToolTip="Обновить информацию о пользователе из магазина" Width="20">
                                <Image Source="/SellAvi;component/Resources/loop.png"></Image>
                            </Button>
                            <Button Command="{Binding DropCredentialsCommand}" CommandParameter="{Binding ElementName=UserItem, Path=DataContext}" ToolTip="Выйти из магазина и забыть пароль" Width="20">
                                <Image Source="/SellAvi;component/Resources/trackback.png"></Image>
                            </Button>
                            <Button Command="{Binding DeleteUserCommand}" CommandParameter="{Binding ElementName=UserItem, Path=DataContext}" ToolTip="Удалить пользователя из программы" Width="20">
                                <Image Source="/SellAvi;component/Resources/trash.png"></Image>
                            </Button>
                        </StackPanel>
                        <GroupBox Grid.Column="1" Margin="5,0,5,0" Header="Данные для входа" HorizontalAlignment="Left" Width="160" Height="105"  VerticalAlignment="Top">
                            <StackPanel>
                                <TextBox HorizontalAlignment="Left" Height="20" Width="145" Text="{Binding Path=UserName}" VerticalAlignment="Top"/>
                                <TextBox HorizontalAlignment="Left" Height="20" Width="145" Text="{Binding Path=UserPassword}" VerticalAlignment="Top" Foreground="LightGray"/>
                                <TextBox HorizontalAlignment="Left" Height="40" Width="145" Text="{Binding Path=UserCookie}" IsReadOnly="True" VerticalAlignment="Top" TextWrapping="Wrap" FontSize="8" Background="WhiteSmoke"/>
                            </StackPanel>
                        </GroupBox>
                        <GroupBox Grid.Column="2" Margin="5,0,5,0" Header="Сведения из магазина" HorizontalAlignment="Left" Width="200" Height="105"  VerticalAlignment="Top">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="20" />
                                    <RowDefinition Height="20" />
                                    <RowDefinition Height="20" />
                                    <RowDefinition Height="20" />
                                </Grid.RowDefinitions>

                                <Label>Магазин:</Label>
                                <TextBlock Grid.Column="1" Text="{Binding CompanyName}"/>
                                <Label Grid.Row="1">Владелец:</Label>
                                <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding CompanyManager}" />
                                <Label Grid.Row="2">E-mail:</Label>
                                <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding CompanyEmail}" />
                                <Label Grid.Row="3">Телефон:</Label>
                                <ComboBox Grid.Row="3" Grid.Column="1" ItemsSource="{Binding SplitedCompanyPhones}" SelectedIndex="0" x:Name="PhonesComboBox">
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="SelectionChanged">
                                            <command:EventToCommand Command="{Binding RelativeSource={RelativeSource AncestorType=Window},Path=DataContext.SetDefaultPhoneCommand}">
                                                <command:EventToCommand.CommandParameter>
                                                    <MultiBinding Converter="{StaticResource apc}">
                                                        <Binding Path="DataContext" ElementName="UserItem"/>
                                                        <Binding Path="SelectedIndex" ElementName="PhonesComboBox"/>
                                                    </MultiBinding>
                                                </command:EventToCommand.CommandParameter>
                                            </command:EventToCommand>
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </ComboBox>
                            </Grid>
                        </GroupBox>

                        <GroupBox Grid.Column="3" Margin="5,0,5,0" Header="Статистика пользователя" HorizontalAlignment="Left" Width="160" Height="105"  VerticalAlignment="Top">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="20" />
                                    <RowDefinition Height="20" />
                                    <RowDefinition Height="20" />
                                    <RowDefinition Height="20" />
                                </Grid.RowDefinitions>

                                <Label>Количество товаров:</Label>
                                <TextBlock Grid.Column="1" Text="{Binding ProductsCount}"/>
                                <Label Grid.Row="1">Собрано:</Label>
                                <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding ProductsParsed}" />
                                <Label Grid.Row="2">Опубликовано:</Label>
                                <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding ProductsPublished}" />
                            </Grid>
                        </GroupBox>
                    </Grid>
                </DataTemplate>
            </ItemsControl.ItemTemplate>

        </ItemsControl>

        <!--<DataGrid x:Name="CredentialsGrid" ItemsSource="{Binding AvitoUsers}"
                      CanUserReorderColumns="True" CanUserResizeColumns="True"
                      CanUserResizeRows="False" CanUserSortColumns="True" CanUserAddRows="False"
                      AlternatingRowBackground="PapayaWhip"  AlternationCount="2" AutoGenerateColumns="False"
                  GridLinesVisibility="None">
            <DataGrid.Columns>

                <DataGridTemplateColumn Header="X" Width="18" IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Background="WhiteSmoke" Command="{Binding Source={StaticResource Locator}, Path=Main.DeleteUserCredentialsCommand}" CommandParameter="{Binding SelectedItem, ElementName=CredentialsGrid}"  ToolTip="Удаление данных авторизации">
                                <Image Source="/Resources/trash.png" />
                            </Button>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTextColumn Header="Id" Binding="{Binding Id}" />
                <DataGridTextColumn Header="Пользователь" Binding="{Binding UserName}" />
                <DataGridTextColumn Header="Пароль" Binding="{Binding UserPassword}" />
                <DataGridTextColumn Header="Cookies" Binding="{Binding UserCookie}" />
            </DataGrid.Columns>

        </DataGrid>-->





        <!--<ScrollViewer VerticalScrollBarVisibility="Auto">
            <ItemsControl ItemsSource="{Binding AvitoUsers}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="20"/>
                                <ColumnDefinition Width="120"/>
                                <ColumnDefinition Width="100"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="16"/>
                            </Grid.ColumnDefinitions>

                            <TextBox Grid.Column="0" Text="{Binding Id}" IsEnabled="False"></TextBox>
                            <TextBox Grid.Column="1" Text="{Binding UserName}"></TextBox>
                            <TextBox Grid.Column="2" Text="{Binding UserPassword}"></TextBox>
                            <TextBox Grid.Column="3" Text="{Binding UserCookie}"></TextBox>
                            <Button Grid.Column="4" DataContext="{Binding Main, Source={StaticResource Locator}}" Command="{Binding DeleteUserCredentialsCommand}">
                                <Image Source="/Resources/trash.png" />
                            </Button>
                            
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>-->




        <!--<ListView  ItemsSource="{Binding RHC}">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Имя пользователя" DisplayMemberBinding="{Binding ParamName}"></GridViewColumn>
                    <GridViewColumn Header="Пароль" DisplayMemberBinding="{Binding ParamValue}"></GridViewColumn>
                    <GridViewColumn>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Button Content="+" Command="Close"></Button>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>

                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>-->

    </Grid>
</Window>
